//
//  LineLabel.m
//  小团购
//
//  Created by 樊荣海 on 15/2/3.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "LineLabel.h"

@implementation LineLabel

- (id)initWithCoder:(NSCoder *)aDecoder {

    if (self == [super initWithCoder:aDecoder]) {

        NSLog(@"initWithCoder");
    }
    
    return self;
}


- (void)setText:(NSString *)text {
    
    [super setText:text];
    
    CGSize size =  [LabelTool sizeOfStr:self.text andFont:self.font andMaxSize:CGSizeMake(100, 60) andLineBreakMode:NSLineBreakByTruncatingTail];
    CGRect rect = self.frame;
    rect.size.width = size.width;
    self.frame = rect;
}


- (void)drawRect:(CGRect)rect {
    
    [super drawRect:rect];
    
    //1.获得上下文
    CGContextRef context =  UIGraphicsGetCurrentContext();
    
    //2.设置颜色
    [[UIColor grayColor] setStroke];
    
    //3.设置宽度
    CGContextSetLineWidth(context, 0.5);
    
    //4.画线--起点
    CGContextMoveToPoint(context, 0, (rect.size.height-5)/2);
    
    //5.画线--终点
    CGContextAddLineToPoint(context, rect.size.width, (rect.size.height-5)/2);
    
    CGContextStrokePath(context);
    
    
}


@end
